package com.sky.web.app;

import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartSerivce;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")

public class AppShoppingCartController {

    @Autowired
    private ShoppingCartSerivce shoppingCartSerivce;

    //添加购物车
    @PostMapping("/add")
    public Result save(@RequestBody ShoppingCart shoppingCart){
        //1.调用Service
        shoppingCartSerivce.save(shoppingCart);
        //2.返回结果
        return Result.success();
    }

    //查询购物车
    @GetMapping("/list")
    public Result findList() {
        //1.调用Service
        List<ShoppingCart> list = shoppingCartSerivce.findList();
        return Result.success(list);
    }

    // 清空购物车
    @DeleteMapping("/clean")
    public Result clean() {
        //1.调用Service
        shoppingCartSerivce.clean();
        //2.返回结果
        return Result.success();
    }

    // 删减少购物车
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCart shoppingCart) {
        //1.调用Service
        shoppingCartSerivce.sub(shoppingCart);
        //2.返回结果
        return Result.success();
    }


}
